package com.neuedu.api.collection;

import java.util.LinkedList;
import java.util.List;

/**
 * @author 金山
 * 项目：javase
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2024/10/2414:48
 */
public class UseLinkedList {
    public static void main(String[] args) {
        LinkedList list = new LinkedList();

        //额外
        list.add("100");
        list.add("200");
        list.add("300");



        //获取第一个元素
       Object objFirst =  list.getFirst();
        System.out.println("objFirst = " + objFirst);
        System.out.println("list = " + list);

        //出队

        // Object pop = list.pop();
        //[100,200,300]
        //100
        System.out.println("list.pop() = " + list.pop());

        // [200,300]
        System.out.println("list.pop() = " + list.pop()); // 200   [300]
        System.out.println("list.pop() = " + list.pop()); // 300    []
        System.out.println("list.pop() = " + list.poll()); // null
        System.out.println("list.pop() = " + list.poll()); // null
        System.out.println("list.pop() = " + list.poll()); // null
        System.out.println("list.pop() = " + list.poll()); // null
        System.out.println("list.pop() = " + list.poll()); // null
        System.out.println("list.pop() = " + list.poll()); // null
        System.out.println("list.pop() = " + list.poll()); // null

        // System.out.println("list.pop() = " + list.pop()); //  Exception in thread "main" java.util.NoSuchElementException


        System.out.println("list = " + list);




        LinkedList linkedList2 = new LinkedList();
        linkedList2.add(1);
        linkedList2.add(2);
        linkedList2.add(3);

        linkedList2.addFirst(0);
        linkedList2.addLast(4);
        System.out.println("linkedList2 = " + linkedList2);

        System.out.println("linkedList2.getFirst() = " + linkedList2.getFirst());
        System.out.println("linkedList2.getLast() = " + linkedList2.getLast());
        System.out.println("linkedList2 = " + linkedList2);

        System.out.println("linkedList2.getFirst() = " + linkedList2.removeFirst());
        System.out.println("linkedList2.removeLast() = " + linkedList2.removeLast());
        System.out.println("linkedList2 = " + linkedList2);

        System.out.println("linkedList2.getFirst() = " + linkedList2.removeFirst());
        System.out.println("linkedList2.removeLast() = " + linkedList2.removeLast());
        System.out.println("linkedList2 = " + linkedList2);

        System.out.println("linkedList2.getFirst() = " + linkedList2.removeFirst());
        System.out.println("linkedList2.removeLast() = " + linkedList2.removeLast());
        System.out.println("linkedList2 = " + linkedList2);




    }








}
